// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.QueryDsl;

public sealed partial class RuleQuery
{
	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("boost")]
	public float? Boost { get; set; }
	[JsonInclude, JsonPropertyName("match_criteria")]
	public object MatchCriteria { get; set; }
	[JsonInclude, JsonPropertyName("organic")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query Organic { get; set; }
	[JsonInclude, JsonPropertyName("_name")]
	public string? QueryName { get; set; }
	[JsonInclude, JsonPropertyName("ruleset_id")]
	public Elastic.Clients.Elasticsearch.Serverless.Id RulesetId { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query(RuleQuery ruleQuery) => Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query.RuleQuery(ruleQuery);
}

public sealed partial class RuleQueryDescriptor<TDocument> : SerializableDescriptor<RuleQueryDescriptor<TDocument>>
{
	internal RuleQueryDescriptor(Action<RuleQueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public RuleQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private object MatchCriteriaValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query OrganicValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> OrganicDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> OrganicDescriptorAction { get; set; }
	private string? QueryNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Id RulesetIdValue { get; set; }

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public RuleQueryDescriptor<TDocument> Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	public RuleQueryDescriptor<TDocument> MatchCriteria(object matchCriteria)
	{
		MatchCriteriaValue = matchCriteria;
		return Self;
	}

	public RuleQueryDescriptor<TDocument> Organic(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query organic)
	{
		OrganicDescriptor = null;
		OrganicDescriptorAction = null;
		OrganicValue = organic;
		return Self;
	}

	public RuleQueryDescriptor<TDocument> Organic(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		OrganicValue = null;
		OrganicDescriptorAction = null;
		OrganicDescriptor = descriptor;
		return Self;
	}

	public RuleQueryDescriptor<TDocument> Organic(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		OrganicValue = null;
		OrganicDescriptor = null;
		OrganicDescriptorAction = configure;
		return Self;
	}

	public RuleQueryDescriptor<TDocument> QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	public RuleQueryDescriptor<TDocument> RulesetId(Elastic.Clients.Elasticsearch.Serverless.Id rulesetId)
	{
		RulesetIdValue = rulesetId;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		writer.WritePropertyName("match_criteria");
		JsonSerializer.Serialize(writer, MatchCriteriaValue, options);
		if (OrganicDescriptor is not null)
		{
			writer.WritePropertyName("organic");
			JsonSerializer.Serialize(writer, OrganicDescriptor, options);
		}
		else if (OrganicDescriptorAction is not null)
		{
			writer.WritePropertyName("organic");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>(OrganicDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("organic");
			JsonSerializer.Serialize(writer, OrganicValue, options);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		writer.WritePropertyName("ruleset_id");
		JsonSerializer.Serialize(writer, RulesetIdValue, options);
		writer.WriteEndObject();
	}
}

public sealed partial class RuleQueryDescriptor : SerializableDescriptor<RuleQueryDescriptor>
{
	internal RuleQueryDescriptor(Action<RuleQueryDescriptor> configure) => configure.Invoke(this);

	public RuleQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private object MatchCriteriaValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query OrganicValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor OrganicDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> OrganicDescriptorAction { get; set; }
	private string? QueryNameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Id RulesetIdValue { get; set; }

	/// <summary>
	/// <para>Floating point number used to decrease or increase the relevance scores of the query.<br/>Boost values are relative to the default value of 1.0.<br/>A boost value between 0 and 1.0 decreases the relevance score.<br/>A value greater than 1.0 increases the relevance score.</para>
	/// </summary>
	public RuleQueryDescriptor Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	public RuleQueryDescriptor MatchCriteria(object matchCriteria)
	{
		MatchCriteriaValue = matchCriteria;
		return Self;
	}

	public RuleQueryDescriptor Organic(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query organic)
	{
		OrganicDescriptor = null;
		OrganicDescriptorAction = null;
		OrganicValue = organic;
		return Self;
	}

	public RuleQueryDescriptor Organic(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor descriptor)
	{
		OrganicValue = null;
		OrganicDescriptorAction = null;
		OrganicDescriptor = descriptor;
		return Self;
	}

	public RuleQueryDescriptor Organic(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> configure)
	{
		OrganicValue = null;
		OrganicDescriptor = null;
		OrganicDescriptorAction = configure;
		return Self;
	}

	public RuleQueryDescriptor QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	public RuleQueryDescriptor RulesetId(Elastic.Clients.Elasticsearch.Serverless.Id rulesetId)
	{
		RulesetIdValue = rulesetId;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		writer.WritePropertyName("match_criteria");
		JsonSerializer.Serialize(writer, MatchCriteriaValue, options);
		if (OrganicDescriptor is not null)
		{
			writer.WritePropertyName("organic");
			JsonSerializer.Serialize(writer, OrganicDescriptor, options);
		}
		else if (OrganicDescriptorAction is not null)
		{
			writer.WritePropertyName("organic");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor(OrganicDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("organic");
			JsonSerializer.Serialize(writer, OrganicValue, options);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		writer.WritePropertyName("ruleset_id");
		JsonSerializer.Serialize(writer, RulesetIdValue, options);
		writer.WriteEndObject();
	}
}